﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Web.UI.HtmlControls;
namespace cnFederal.Fa_Forms
{
    public partial class Nationality : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CnfImages.Load();
            int id = Convert.ToInt32( Request.QueryString["Id"]);
            LoadObject(id);
            //fbLikeButton.Url = Request.Url.AbsoluteUri;
            //fbLikeButton.ShowFaces = false;
        }


        public string GetAbsolutUri()
        {
            return HttpContext.Current.Request.Url.AbsoluteUri;
        }
        public int MainContentHeight
        {
            get;
            set;
        }
        private void LoadObject(int id)
        {

            Nation nation = Nations.GetFaPostById(id);
            if (nation != null)
            {
                this.MainContentHeight = nation.MainContent.Length / 10;
                
                TextBoxIngress.Text = nation.Header;
                TextBoxTitle.Text = nation.Title + Environment.NewLine +
                    " <br /> Date:  " + nation.DateRegistered.ToShortDateString() + Environment.NewLine;

                TextBoxContent.Text = nation.MainContent.Replace("\n", "<br>"); ;
                Image1.ImageUrl = nation.ImageUrl;
                SetFacebookMeta(nation.Title, nation.ImageUrl, nation.Header);
                this.TextBoxContent.Focus();

            }




        }

        public void SetFacebookMeta(string title, string imageUrl, string description)
        {
            HtmlMeta tag = new HtmlMeta();
            tag.Attributes.Add("property", "og:title");
            tag.Content = title;
            Page.Header.Controls.Add(tag);
            HtmlMeta imgUrl = new HtmlMeta();
            imgUrl.Attributes.Add("property", "og:image");
            imgUrl.Content = imageUrl;
            Page.Header.Controls.Add(imgUrl);

            HtmlMeta des = new HtmlMeta();
            des.Attributes.Add("property", "og:description");
            des.Content = description;
            Page.Header.Controls.Add(des);
        }
    }
}